package com.mentaleye.biz.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.TransactionBean;
import com.mentaleye.biz.TransactionBiz;
import com.mentaleye.service.TransactionService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;

@Service
public class TransactionBizImpl implements TransactionBiz{
	
	@Autowired private TransactionService transactionService;
	private static Logger logger = Logger.getLogger(TransactionBizImpl.class);
	
	@Override
	public CommonResult addTransaction(TransactionBean transactionBean){
		CommonResult result = new CommonResult();
		boolean success = false;
		try {
			success = transactionService.addTransaction(transactionBean);
			result.setIsSuccess(success);
		} catch (Exception e) {
			logger.error("交易添加异常", e);
		}
		return result;
	}
	
	@Override
	public CommonResult modifyTransaction(TransactionBean transactionBean){
		CommonResult result = new CommonResult();
		boolean success = false;
		try {
			success = transactionService.addTransaction(transactionBean);
			result.setIsSuccess(success);
		} catch (Exception e) {
			logger.error("交易修改异常", e);
		}
		return result;
	}
	
	@Override
	public CommonResult modifyTransaction(String transactionId,Integer transactionState){
		TransactionBean bean = new TransactionBean();
		bean.setTransactionId(transactionId);
		bean.setTransactionState(transactionState);
		return modifyTransaction(bean);
	}
	
	@Override
	public CommonResult modifyTransaction(String transactionId,String transactionDesc){
		TransactionBean bean = new TransactionBean();
		bean.setTransactionId(transactionId);
		bean.setTransactionDesc(transactionDesc);
		return modifyTransaction(bean);
	}
	
	@Override
	public CommonResult modifyTransaction(String transactionId,Integer transactionState,String transactionDesc){
		TransactionBean bean = new TransactionBean();
		bean.setTransactionId(transactionId);
		bean.setTransactionState(transactionState);
		bean.setTransactionDesc(transactionDesc);
		return modifyTransaction(bean);
	}
	
	@Override
	public CommonResult removeTransaction(String transactionId){
		boolean success  = false;
		try {
			success = transactionService.removeTransaction(transactionId);
		} catch (Exception e) {
			logger.error("交易删除异常", e);
		}
		return new CommonResult(success);
	}
	
	@Override
	public TransactionBean queryTransactionByKey(String transactionId){
		TransactionBean transactionBean = null;
		try {
			transactionBean = transactionService.queryTransactionByKey(transactionId);
		} catch (Exception e) {
			logger.error("根据交易编号查询异常", e);
		}
		return transactionBean;
	}
	
	@Override
	public List<TransactionBean> queryTransactionByRelationProcessId(String relationProcessId){
		List<TransactionBean> transactionBeanList = null;
		try {
			transactionBeanList = transactionService.queryTransactionByRelationProcessId(relationProcessId);
		} catch (Exception e) {
			logger.error("根据关联流程编号查询异常", e);
		}
		return transactionBeanList;
	}
	
	@Override
	public List<TransactionBean> queryTransactionByTraObjectId(Integer traObjectId){
		List<TransactionBean> transactionBeanList = null;
		try {
			transactionBeanList = transactionService.queryTransactionByTraObjectId(traObjectId);
		} catch (Exception e) {
			logger.error("根据交易对象编号查询异常", e);
		}
		return transactionBeanList;
	}
	
	@Override
	public List<TransactionBean> queryTransactionByBeTransactionId(Integer beTransactionId){
		List<TransactionBean> transactionBeanList = null;
		try {
			transactionBeanList = transactionService.queryTransactionByBeTransactionId(beTransactionId);
		} catch (Exception e) {
			logger.error("根据被交易对象编号查询异常", e);
		}
		return transactionBeanList;
	}
	
	@Override
	public void queryTransactionByMap(CommonPage commonPage){
		try {
			transactionService.queryTransactionByMap(commonPage);
		} catch (Exception e) {
			logger.error("根据条件查询交易分页异常", e);
		}
	}
}
